<template>
  <div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- 左侧分类 -->
        <HomeCategory />
        <!-- banner轮播图 -->
        <HomeBanner/>
        <!-- 新鲜好物 -->
        <HomePannel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
          <template #right>
            <xtx-more></xtx-more>
          </template>
          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in newList" :key="item.id">
                <RouterLink :to="`/good/${item.id}`">
                  <img :src="item.picture" alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </HomePannel>
        <!-- 人气推荐 -->
        <HomePannel title="人气推荐" sub-title="人气推荐 不容错过">
          <template #right></template>
          <template #main>
            <ul  class="goods-list">
              <li v-for="item in hotList" :key="item.id">
                <RouterLink to="/">
                  <img v-lazy-img="item.picture">
                  <p class="name">{{item.title}}</p>
                  <p class="desc">{{item.alt}}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </HomePannel>
      </div>
    </div>
  </div>
</template>

<script>
import HomeCategory from './components/home-category'
import HomeBanner from './components/home-banner'
import HomePannel from './components/home-pannel'
import { findNew, findHot } from '@/api/home'
import { ref } from 'vue'
export default {
  name: 'home-index',
  components: {
    HomeCategory,
    HomeBanner,
    HomePannel
  },
  setup () {
    // 新鲜好物
    const newList = ref([])
    const hotList = ref([])
    async function getnewlist () {
      const res = await findNew()
      newList.value = res.result
    }
    async function githotList () {
      const res = await findHot()
      hotList.value = res.result
      console.log(hotList.value)
    }
    getnewlist()
    githotList()
    return {
      newList,
      hotList
    }
  }
}
</script>

<style lang="less" scoped>
// 1. 导入var.less
// @import "~@/styles/var.less";
// 2. 使用内部的变量
.test {
  color: @xtxColor;
}
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
